﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace GitHub.UI
{
	// http://stackoverflow.com/questions/12125764/change-style-of-last-item-in-listbox
	public class IsLastItemInContainerConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			DependencyObject item = (DependencyObject)value;
			ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(item);

			return ic.ItemContainerGenerator.IndexFromContainer(item) == ic.Items.Count - 1;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}